<?php

namespace App\Http\Controllers\Account;


use App\Rules\VerificationCodeRule;
use App\Services\CodeService;
use App\User;
use Illuminate\Http\Request;

class ForgetPasswordController extends Controller
{
    //
    public function create()
    {
        return view('account.forgetpassword');
    }

    public function store(Request $request, CodeService $codeService)
    {
//

        $request->validate(
            ['account' => 'required', 'password' => ['required', 'min:5', 'confirmed'],
                'code' => [new VerificationCodeRule($request->account), 'required']
            ]);
        $user = User::where($this->username(), $request->account)->first();
        $user->password = $request->password;
        $user->save();
        return response()->json(['message' => '密码修改成功', 'route' => route('login')]);
    }
}
